
import { _decorator, Component, Node, SpriteFrame, Sprite } from 'cc';
import PlayerData from '../../Script/Common/PlayerData';
import yyComponent from '../../Script/Common/yyComponent';
import { EventType } from '../../Script/GameSpecial/GameEventType';
import { GlobalEnum } from '../../Script/GameSpecial/GlobalEnum';
import { ShopDataCfg, ShopDataType } from '../../Script/GameSpecial/shopDataCfg';
const { ccclass, property } = _decorator;

@ccclass('AwardPage')
export class AwardPage extends yyComponent {
    @property(Sprite)
    icon: Sprite = null;

    _cfg: ShopDataType = null;
    //展示商品--只展示非金币类奖品    
    showAward(sf: SpriteFrame, type: number, id: number) {
        this.node.active = true;
        this._cfg = ShopDataCfg[type][id];
        this.icon.spriteFrame = sf;
        //音效
        this.emit(EventType.Common.AudioEvent.playEffect, GlobalEnum.AudioClip.getSkin);
    }

    hide() {
        this.node.active = false;
    }
    //领取
    onGetAwardClick() {
        this.emit(EventType.Common.AudioEvent.playClickBtn);

        let shopData = PlayerData.getData("gameData.shopData");
        shopData[this._cfg.type][this._cfg.id] = true;
        this.emit(EventType.Common.PlayerDataEvent.updatePlayerData, {
            attribute: "gameData.shopData",
            value: shopData,
            mode: "=",
            emit: true,
            save: true,
        });
        //隐藏
        this.hide();
    }

}


